package com.ygp.dtp.core.context;

import com.google.common.collect.Maps;
import com.ygp.dtp.common.dto.NotifyItem;
import com.ygp.dtp.common.dto.NotifyPlatform;
import com.ygp.dtp.core.thread.DynamicThreadPoolExecutor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * @description: 动态数据源动态处理NotifyPlatform
 * @motto: 代码源于生活，高于生活艺术
 * @author: zhouhengzhe
 * @date: 2022/8/8 11:03
 * @since 1.0
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DynamicThreadPoolContext {

    private DynamicThreadPoolExecutor dynamicThreadPoolExecutor;

    private List<NotifyPlatform> platforms;

    private NotifyItem notifyItem;

    /**
     * 获取对应平台对应的相关配置
     *
     * @param platform 品台名
     * @return
     */
    public NotifyPlatform getPlatform(String platform) {
        Map<String, NotifyPlatform> map = Maps.newHashMap();
        if (!CollectionUtils.isEmpty(platforms)) {
            map = Maps.uniqueIndex(platforms, notifyPlatform -> notifyPlatform.getPlatform().toLowerCase());
        }
        return map.get(platform.toLowerCase());
    }
}
